package com.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.fhMall.request.DeleteMemberCouponRequest;
import com.fhMall.request.QueryMemberCouponRequest;
import com.fhMall.request.SaveMemberCouponRequest;
import com.wechat.feign.FhEmalllCouponApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 程序名：.java<br>
 * 程序功能 <br>
 * 作成者：xianlin <br>
 * 日期：2019-09-19 20:46<br>
 * 修改履历 <br>
 * 项目名    状态      作成者      日期   <br>
 * --------------------------------------- <br>
 * 新规      xianlin   2019-09-19 20:46 <br>
 * ----------------------------- <br>
 */
@RestController
@RequestMapping("wechat/coupon")
@Api(tags = "微商城优惠券")
public class WechatCouponController extends BaseController {

    @Autowired
    private FhEmalllCouponApi fhEmalllCouponApi;

    /**
     * 查询用户优惠券
     * @return 用户优惠券
     */
    @ApiOperation(value="查询用户优惠券")
    @GetMapping(value = "/queryMemberCoupon")
    public JSONObject queryMemberCoupon(QueryMemberCouponRequest queryMemberCouponRequest) {
        queryMemberCouponRequest.setMemberId(this.getUserId());
//        queryMemberCouponRequest.setStatus(1);queryMemberCouponRequest.setPageNo(1);queryMemberCouponRequest.setPageSize(20);
        String result = fhEmalllCouponApi.queryMemberCoupon(queryMemberCouponRequest);
        return JSONObject.parseObject(result);
    }

    /**
     * 添加用户优惠券
     * @return
     */
    @ApiOperation(value="添加用户优惠券")
    @PostMapping(value = "/saveMemberCoupon")
    public JSONObject saveMemberCoupon(@RequestBody SaveMemberCouponRequest saveMemberCouponRequest) {
        String result = fhEmalllCouponApi.saveMemberCoupon(saveMemberCouponRequest);
        return JSONObject.parseObject(result);
    }

    /**
     * 用户删除优惠券
     * @return
     */
    @ApiOperation(value="用户删除优惠券")
    @PostMapping(value = "/deleteMemberCoupon")
    public JSONObject deleteMemberCoupon(@RequestBody DeleteMemberCouponRequest deleteMemberCouponRequest) {
        String result = fhEmalllCouponApi.deleteMemberCoupon(deleteMemberCouponRequest);
        return JSONObject.parseObject(result);
    }

}
